import React, { Component } from 'react'
import {Form,Input,Button,DatePicker,TimePicker,Select ,message} from "antd"
import "./index.scss"
import { request } from '../../api';
const { TextArea } = Input;
const { RangePicker } = DatePicker;
const { Option } = Select;
export default class AnnoAdd extends Component {
    AnnoAdd=(fieldsValue)=>{
        const rangeValue = fieldsValue['timelist'];
        const value = {
            ...fieldsValue,
            'timelist': [rangeValue[0].format('YYYY-MM-DD'), rangeValue[1].format('YYYY-MM-DD')],
            'phone':JSON.parse(localStorage.getItem("userinfo")).phone,
            'username':JSON.parse(localStorage.getItem("userinfo")).username
        }
        request.addanno(value)
        .then(res=>{
            if(res.code==200){
                message.success(res.msg)
                this.annoFrom.resetFields()
            }else{
                message.error("未知错误,请联系管理员")
            }
        })
    }
    render() {
        return (
            <div className="site-layout-background" style={{ padding: 24, minHeight: 760 }}>
                <h2>添加公告</h2>
                <Form className="addFrom" onFinish={this.AnnoAdd} ref={el=>this.annoFrom=el}>
                    <Form.Item name="title" label="标题" rules={[{ required: true, message: 'Please input your title!' }]}>
                        <Input allowClear></Input>
                    </Form.Item>
                    <Form.Item name="content" label="内容" rules={[{ required: true, message: 'Please input your content!' }]}>
                        <TextArea allowClear></TextArea>
                    </Form.Item>
                    <Form.Item name="timelist" label="时间" rules={[{ required: true, message: 'Please input your time!' }]}>
                        <RangePicker className="fromTime"></RangePicker>
                    </Form.Item>
                    <Form.Item name="role" label="权限" rules={[{ required: true, message: 'Please input your role!' }]}>
                        <Select placeholder="0 用户可观看 1 管理员及以上">
                            <Option key="0">0</Option>
                            <Option key="1">1</Option>
                        </Select>
                    </Form.Item>
                    <Form.Item>
                        <Button type="submit" htmlType="submit">
                            添加
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        )
    }
}
